<?php
/**
 * Block
 * 
 * PHP4 Compatibility
 *   - Extending Object makes __construct() the constructor.
 * 
 * @package default
 * @author Daryl Koopersmith
 **/

class Block extends Object {
	var $name;
	var $views;
	var $default_views;
	/**
	 * TODO: Create a hook for before and after the run function is run.
	 */
	function __construct($name, $views = null) {
		global $template;
		if (empty($template))
			$template = nspc_get_template();
			
		
		$this->name = $name;
	
		if(isset($default_views))
			$this->views = $default_views;
	
		if(isset($views))
			set_view($views);
	}
	
	
	/**
	 * Gets the view for a template.
	 *
	 * @param string $template Optional. Default = "index"
	 * @return function
	 * @author Daryl Koopersmith
	 */
	function get_view($template = "index") {
		return $views[$template];
	}
	
	/**
	 * Sets a view for each template.
	 *
	 * @param mixed $template Accepts a string or an associative array of ($template=>$view).
	 * @param function $view Optional.
	 * @author Daryl Koopersmith
	 */
	function set_view($template, $view = null) {
		if (is_array($template)) {
			foreach($template as $key => $value) {
				$views[$key] => $value;
			}
		} else {
			$views[$template] = $view;			
		}
	}
	
	/**
	 * Calls the hooks and generates the output.
	 *
	 * @author Daryl Koopersmith
	 */
	function run() {
		for ($template as $value) {
			if(isset($value))
				$view = $value;
		}
		get_view($view);
	}
	
	/**
	 * before & after
	 * 
	 * add_action to each hook
	 *
	 * @author Daryl Koopersmith
	 */
	function before($action) {
		
	}
	
	function after($action) {
		
	}
}

?>